<template>
  <div>
    <a-form :form="form">
      <a-row :gutter="48">
        <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}">
          <a-form-item label="院系">
            <a-select showSearch optionFilterProp="children" v-decorator="[
                    'ssyxm',
					{initialValue:postParams.ssyxm}
                    ]"
              disabled @change='yxChange'>
              <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{i.dwh+"-"+ i.dwmc }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}">
          <a-form-item label="专业">
            <a-select showSearch optionFilterProp="children" v-decorator="[
                    'sszym',
					{initialValue:postParams.sszym}
                    ]"
              disabled @change='zyChange'>
              <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh+"-"+i.zymc }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}" v-if='info.yjfxm'>
          <a-form-item label="研究方向">
            <a-select showSearch optionFilterProp="children" v-decorator="[
                    'yjfxm',
					{initialValue:postParams.yjfxm}
                    ]"
              disabled>
              <a-select-option v-for="i in selectMenu.yjfx" :key="i.id" :value="i.yjfxm">{{ i.yjfxm.substring(i.yjfxm.length-2) +"-"+ i.yjfxmc }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col ::sm="{span:12}" :lg="{span:6}" :xl="{span:6}">
          <a-form-item label="招生人数">
            <a-input v-decorator="[
                    'zsrs',
					{initialValue:postParams.zsrs}
                    ]"
              :disabled="disabledStop" disabled />
          </a-form-item>
        </a-col>
        <a-col :sm="{span:12}" :lg="{span:6}" :xl="{span:6}">
          <a-form-item label="招生年度">
            <a-select showSearch optionFilterProp="children" v-decorator="[
                    'zsxn',
					{initialValue:postParams.zsxn}
                    ]"
              :disabled="disabledStop" disabled>
              <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :lg="24" :md="24" :sm="24">
            <a-form-item
                label="考试科目"
            >
                <a-textarea  v-decorator="[
                'kskm',
                {initialValue:postParams.kskm}
                ]" :disabled="disabledStop" rows="4" disabled/>
            </a-form-item>
        </a-col>
        <a-col :lg="24" :md="24" :sm="24">
          <a-form-item label="复试科目">
            <a-textarea v-decorator="[
                    'fskm',
					{initialValue:postParams.fskm}
                    ]"
              :disabled="disabledStop" rows="4" disabled />
          </a-form-item>
        </a-col>
        <a-col :lg="24" :md="24" :sm="24">
          <a-form-item label="加试科目">
            <a-textarea v-decorator="[
                    'jskm',
                    {initialValue:postParams.jskm}
                    ]"
              :disabled="disabledStop" rows="4" disabled />
          </a-form-item>
        </a-col>
        <a-col :lg="24" :md="24" :sm="24">
          <a-form-item label="备注">
            <a-textarea v-decorator="[
                    'note',
					{initialValue:postParams.note}
                    ]"
              :disabled="disabledStop" rows="4" disabled />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </div>
</template>

<script>
  import {
    mapState
  } from 'vuex'

  const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

  export default {
    props: {
      confirmHandleVisiable: {
        default: false
      },
      info: {
        default: () => ({})
      },
      // 是否禁止编辑
      disabledStop: {
        default: true
      }
    },
    data() {
      return {
        loading: false,
        selectMenu: {
          yx: [], // 院系
          zy: [] //专业
        },
        postParams: {

        }
      }
    },
    beforeCreate() {
      this.form = this.$form.createForm(this)
    },
    computed: {
      ...mapState({
        systemInfo: state => state.app.systemInfo,
        TYPE0321: state => state.app['TYPE0321'], // 是否在岗
        TYPE0126: state => state.app['TYPE0126'], // 年级
        TYPE0011: state => state.app['TYPE0011'] // 性别
      })
    },
    created() {
      selectArr.forEach(v => {
        this.$store.dispatch('app/setDictionary', v)
      })
      this.form.setFieldsValue({})
      this.postParams = this.info
      for (let key in this.info) {
        if (key == 'zsxn' || key == 'ssyxm' || key == 'sszym' || key == 'yjfxm' || key == 'zsrs' || key == 'fskm' ||
          key == 'jskm' || key == 'kskm' || key == 'zsxn' || key == 'id' || key == 'note') {
          this.postParams[key] = this.info[key]
          this.form.getFieldDecorator(key, {
            initialValue: this.postParams[key]
          })
        }
      }
      this.initSelectMenu()
      this.getProssion(this.info.ssyxm)
      this.getDirec(this.info.sszym)
    },
    watch: {
      info() {
        this.form.resetFields()
        this.postParams = this.info
        for (let key in this.info) {
          if (key == 'zsxn' || key == 'ssyxm' || key == 'sszym' || key == 'yjfxm' || key == 'zsrs' || key == 'fskm' ||
            key == 'jskm' || key == 'kskm' || key == 'zsxn' || key == 'id' || key == 'note') {
            this.postParams[key] = this.info[key]
            this.form.getFieldDecorator(key, {
              initialValue: this.postParams[key]
            })
          }
        }
        this.initSelectMenu()
        this.getProssion(this.info.ssyxm)
        if(this.info.sszym){
          this.getDirec(this.info.sszym)
        }
      }
    },
    methods: {
      initSelectMenu() {
        let allRequest = [
          this.$api.base.collegeAll()
        ]
        Promise.all(allRequest).then(res => {
          this.selectMenu = {
            yx: res[0].data
          }
        })
      },
      yxChange(code) {
        this.form.setFieldsValue({
          'sszym': ''
        })
        this.getProssion(code)
      },
      // 获取专业
      getProssion(code) {
        // 获取专业
        this.$api.base.majorAll({
          lsdwh: code
        }).then(res => {
          this.$set(this.selectMenu, 'zy', res.data)
        })
      },
      zyChange(code) {
        this.form.setFieldsValue({
          'yjfxm': ''
        })
        this.getDirec(code)
      },
      // 获取研究方向
      getDirec(code) {
        this.$api.base.searchDirectory({
          ssyxm: this.form.getFieldValue('ssyxm'),
          zsxn: this.form.getFieldValue('zsxn'),
          sszym: code,
           xwccm: 2
        }).then(res => {
          this.$set(this.selectMenu, 'yjfx', res.data)
        })
      },
      // 关闭
      onClose() {
        this.form.resetFields()
        this.$emit('close')
      },
      // 验证数据并输出
      GetInfo() {
        this.form.validateFields((err, values) => {
          if (err) {
            this.$message.error("请选择必填项")
          } else {
            console.log(this.info)
            // if(!this.info || !this.info.zsSsszszyml || !this.info.zsSsszszyml.id){
            //   this.$api.recruitstat.setUpByDirectoriesFirstAdd(this.form.getFieldsValue()).then(res => {
            //     var newData = Object.assign(res.data,this.form.getFieldsValue())
            //     console.log('1',newData)
            //     // return newData
            //     this.$emit('getInfoValue',newData)
            //   }).finally(() => {
            //     this.loadingBtn = false
            //   })
            // }else{
            var params = ''
            this.$emit('getInfoValue', params)
            // params = Object.assign({
            //   'id': this.info.zsSsszszyml.id
            // }, this.form.getFieldsValue())
            // console.log(this.form.getFieldsValue())
            // if (this.info.yjfxm) {
            //   this.$api.recruitstat.setUpByDirectoriesFirstUpdate(params).then(res => {
            //     console.log('2', params)
            //     this.$emit('getInfoValue', params)
            //   }).finally(() => {
            //     this.loadingBtn = false
            //   })
            // } else {
            //   this.$api.recruitstat.setUpBySpecialtyFirstUpdate(params).then(res => {
            //     console.log('2', params)
            //     this.$emit('getInfoValue', params)
            //   }).finally(() => {
            //     this.loadingBtn = false
            //   })
            // }
            // }
          }
        })
      }
    }
  }
</script>

<style lang="less">
  .fullscreen {
    .ant-drawer-wrapper-body {
      height: 100%;
      overflow: auto;
    }
  }
</style>
